<?php
require_once('include/class.php');
$dd=new data();
$type=isset($_REQUEST['type'])?$_REQUEST['type']:'get';
if ($type=='add'){
	$content=addslashes($_REQUEST['content']);
	$data=array('content'=>$content,'write_time'=>date("Y-m-d H:i:s"));
	$record_id=$dd->update($data,'book','insert');
	if (is_numeric($record_id))
		echo $record_id;
	else
		echo '0';
}elseif ($type=='get'){
	$content_id=$_REQUEST['id'];
	$a=$dd->get('book',$content_id,array('content'));
	if ($a && $a->num_rows == 1){
		$record= $a->fetch_assoc ();
		echo $record['content'];
	}
}elseif ($type=='get_catalog'){
	$catalog_id=$_REQUEST['catalog_id'];
	$dd=new data();
	$a=$dd->preview(array('id','catalog_name','father_id','child_type','link_dir'),'catalog',null,null,'catalog_type="'.$catalog_id.'" order by arrange_id ASC, child_type ASC');
	$des_array = array ();
	if ($a){
		if ($a)
			While ($des_row = $a->fetch_assoc ())
				$des_array[]=$des_row;
	}
	echo json_encode($des_array);
}elseif ($type=='get_photo'){
	$album_id=$_REQUEST['album_id'];
	$dd=new data();
	$a=$dd->preview(array('id'),'file',null,null,'catalog_id='.$album_id);
	$des_array = array ();
	$b=$dd->preview(array('catalog_name'),'catalog',null,null,'display_state=1 and id='.$album_id);
	if ($b){
		$des_row = $b->fetch_assoc ();
		$album_name=$des_row['catalog_name'];
		if ($a)
			While ($des_row = $a->fetch_assoc ())
				$des_array[]=$des_row['id'];
	}
	echo json_encode(array('data'=>$des_array,'album_name'=>$album_name));
}elseif ($type=='get_album'){
	$dd=new data();
	$a=$dd->preview(array('id','catalog_name','link_dir'),'catalog',null,null,'father_id=18 and display_state=1');
	$des_array = array ();
	While ($des_row = $a->fetch_assoc ())
		$des_array[]=$des_row;
	echo json_encode($des_array);
}elseif ($type=='login'){
	$result=array('result'=>false);
	if (isset($_REQUEST['name'])){
		$name=$_REQUEST['name'];
		$name=str_replace('+',' ',$name);
		$au=new authorize();
		$check=$au->check_user($name);
		if ($check){
			$_SESSION['yaoyoa_user']=$check;
			$result=array('result'=>true,'data'=>$check);
		}
		
	}elseif (isset($_SESSION['yaoyoa_user'])&&is_array($_SESSION['yaoyoa_user'])){
		$result=array('result'=>true,'data'=>$_SESSION['yaoyoa_user']);
	}
	echo json_encode($result);
}elseif ($type=='logout'){
	$_SESSION['yaoyoa_user']='';
}